Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

Public Class FrmCrNXTKhuyenMai
    Private thang, nam, kho As String
    Private tiendauky As Double
    Private customerReport As ReportDocument

    Private arg As Integer = 1

    Public Sub setArg(ByVal i As Integer)
        arg = i
    End Sub
    Delegate Sub WaitDelegate()

    Private Sub FrmCrNXTKhuyenMai_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        globalVariale.runWaitting = True
        Dim wd As New WaitDelegate(AddressOf moduleWaitting.runningWait)
        wd.BeginInvoke(Nothing, Nothing)

        Dim sqlQuery As String = ""

        If arg = 1 Then
            sqlQuery = "SELECT * FROM tbl_dot_nhapxuatkhuyenmai where recycleID='" & nam & thang & "' "
            'sqlQuery += " and soluongxuat_trongky <> 0 and thanhtienxuat_trongky <> 0 ;"
        ElseIf arg = 2 Then
            sqlQuery = "SELECT * FROM tbl_dot_nhapxuatkhuyenmai_ketoan where recycleID='" & nam & thang & "'"
            'sqlQuery += " and soluongxuat_trongky <> 0 and thanhtienxuat_trongky <> 0 ;"
            sqlQuery += " AND (soluong_dauky<>0 OR soluongnhap_trongky<>0 OR soluongxuat_trongky<>0 OR soluongcuoiky<>0)ORDER BY ten_bietduoc "
        End If
        Dim reportPath = Application.StartupPath & "\" & "crNhapXuatTonKhuyenMai.rpt"
        customerReport = New ReportDocument()
        customerReport.Load(reportPath)
        customerReport.SetDataSource(moduleReportConfig.GetDataTable(sqlQuery))
        customerReport.SetParameterValue("month", thang)
        customerReport.SetParameterValue("year", nam)
        customerReport.SetParameterValue("TKho", kho)
        If arg = 1 Then
            customerReport.SetParameterValue("KD_KT", "KD")
        Else
            customerReport.SetParameterValue("KD_KT", "KT")
        End If
        Me.CrNXTKhuyenMaiview.ReportSource = customerReport

        globalVariale.runWaitting = False
    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub
    Public Sub setThang(ByVal s As String)
        thang = s
    End Sub

    Public Sub setNam(ByVal s As String)
        nam = s
    End Sub
    Public Sub setKho(ByVal s As String)
        kho = s
    End Sub
End Class
